package main


import (
	"github.com/astaxie/beego"
	"findme-api/controllers"
	"github.com/huichen/wukong/types"
	"time"

	//"github.com/astaxie/beego/plugins/cors"
     _ "findme-api/routers"
)


//只能放在main函数中初始化
func InitSearcher() {
	controllers.Searcher.Init(types.EngineInitOptions{
		IndexerInitOptions: &types.IndexerInitOptions{
			IndexType: types.DocIdsIndex,
			//IndexType: types.FrequenciesIndex,
			//IndexType: types.LocationsIndex,
		},
		SegmenterDictionaries: "./dict/dictionary.txt",
		StopTokenFile:         "./dict/stop_tokens.txt",
	})
	//defer searcher.Close()
}

//启动一个协程,每30秒给前端发消息，维持websocket链接
func websocketheart(udpDatachan chan []byte) {
	for {
		////&&0000000，加速度传感器信息，定位类别，￥GPS，纬度，经度，海拔，净高，定位方式，定位状态码，包长，标签类别，设备ID，公司名
		udpDatachan <- []byte("&&0000000,null,null,null,null,null,null,null,null,null,null,null,websocketheart,所有公司")
		time.Sleep(3*time.Second)
	}
	//ERR:
	////TODO:关闭链接的操作
	//  conn.Close()
}





func main() {
	//初始化日志系统
	controllers.Initlogs()
	//开启UDP服务器协程，从标签接收数据
	//go controllers.Udpserver(controllers.UdpDataChan)
	//开启redia订阅告警服务
	go websocketheart(controllers.UdpDataChan)
	go controllers.Getdatafromredis(controllers.UdpDataChan)
	//初始化搜索器
	InitSearcher()
	beego.SetStaticPath("/static", "static")
	beego.Run()
}

